package _021_10_8

import (
	"strconv"
	"strings"
)

func parseIPv4(ip string) string {
	ip4Item := strings.Split(ip, ".")
	if len(ip4Item) < 4 {
		return "Neither"
	}
	for i := 0; i < len(ip4Item); i++ {
		if ip4Item[i][0] == '0' {
			return "Neither"
		}
		if len(ip4Item) > 3 {
			return "Neither"
		}
		ipN, _ := strconv.Atoi(ip4Item[i])
		if ipN > 255 {
			return "Neither"
		}
	}
	return "IPv4"
}

func parseIPv6(ip string) string {
	ip6Item := strings.Split(ip, ":")
	if len(ip6Item) < 8 {
		return "Neither"
	}
	for i := 0; i < len(ip6Item); i++ {
		if ip6Item[i] == "" {
			return "Neither"
		}
		if ip6Item[i][0] == '0' {
			return "Neither"
		}
		if len(ip6Item[i]) > 4 {
			return "Neither"
		}
	}
	return "IPv6"
}

func solve(IP string) string {
	// write code here
	if strings.Contains(IP, ".") {
		return parseIPv4(IP)
	}
	return parseIPv6(IP)
}
